{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ef2023a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "6b0d08c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "f1 = open('Twitter_User_Handles_labeled_tweets.json')\n",
    "data_tweets = json.load(f1).items()\n",
    "f2 = open('User_demo_profiles.json')\n",
    "data_profile = json.load(f2)\n",
    "user_label = pd.read_csv('labeled_users.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "dac0525b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>is_female</th>\n",
       "      <th>year_born</th>\n",
       "      <th>race</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12488</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1980.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>719703</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1985.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>722153</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1973.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>749003</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1982.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>755531</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1982.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       id  is_female  year_born  race\n",
       "0   12488        0.0     1980.0   4.0\n",
       "1  719703        0.0     1985.0   4.0\n",
       "2  722153        1.0     1973.0   3.0\n",
       "3  749003        0.0     1982.0   5.0\n",
       "4  755531        0.0     1982.0   4.0"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_label.rename(columns={\"user_id\": \"id\"}, inplace = True)\n",
    "user_label[\"id\"] = user_label[\"id\"].astype(int)\n",
    "user_label.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "abfcfe08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>screen_name</th>\n",
       "      <th>description</th>\n",
       "      <th>img_path</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12488</td>\n",
       "      <td>Chad Boyce</td>\n",
       "      <td>djsnipa1</td>\n",
       "      <td>Multimedia Developer, Graphic Designer, DJ, an...</td>\n",
       "      <td>profile pics/60147.jpeg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>719703</td>\n",
       "      <td>Tomato 😷</td>\n",
       "      <td>Tomato</td>\n",
       "      <td>🇭🇰Rise Up!</td>\n",
       "      <td>profile pics/60148.jpeg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>722153</td>\n",
       "      <td>blank</td>\n",
       "      <td>blank</td>\n",
       "      <td>Someone who thinks too much, acts too little.</td>\n",
       "      <td>profile pics/60149.jpeg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>749003</td>\n",
       "      <td>A ring made from a spoon --- E83.31</td>\n",
       "      <td>IYQbd</td>\n",
       "      <td>Has the kind of luck that turns a professional...</td>\n",
       "      <td>profile pics/60150.jpeg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1896301728</td>\n",
       "      <td>عبدالله</td>\n",
       "      <td>755531</td>\n",
       "      <td></td>\n",
       "      <td>profile pics/60151.jpeg</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           id                                 name screen_name  \\\n",
       "0       12488                           Chad Boyce    djsnipa1   \n",
       "1      719703                             Tomato 😷      Tomato   \n",
       "2      722153                                blank       blank   \n",
       "3      749003  A ring made from a spoon --- E83.31       IYQbd   \n",
       "4  1896301728                              عبدالله      755531   \n",
       "\n",
       "                                         description                 img_path  \n",
       "0  Multimedia Developer, Graphic Designer, DJ, an...  profile pics/60147.jpeg  \n",
       "1                                         🇭🇰Rise Up!  profile pics/60148.jpeg  \n",
       "2      Someone who thinks too much, acts too little.  profile pics/60149.jpeg  \n",
       "3  Has the kind of luck that turns a professional...  profile pics/60150.jpeg  \n",
       "4                                                     profile pics/60151.jpeg  "
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_profile = pd.DataFrame(data_profile)\n",
    "data_profile = data_profile[[\"id\", \"name\", \"screen_name\", \"description\", \"img_path\"]]\n",
    "# data_profile = data_profile.set_index([\"id\"])\n",
    "data_profile.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "f4c2c7fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>tweets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12488</td>\n",
       "      <td>[YKAR, a futuristic sans serif font by @Emmera...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>719703</td>\n",
       "      <td>[In other words, it’s good news about the vacc...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>749003</td>\n",
       "      <td>[would it be fair to call lil nas x the first ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>822540</td>\n",
       "      <td>[@Asmongold ❤️ 🙏, @Hunter4J @Wario64 bonk, @FF...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>865071</td>\n",
       "      <td>[@robo_james How about pizza dipped in water 🤦...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       id                                             tweets\n",
       "0   12488  [YKAR, a futuristic sans serif font by @Emmera...\n",
       "1  719703  [In other words, it’s good news about the vacc...\n",
       "2  749003  [would it be fair to call lil nas x the first ...\n",
       "3  822540  [@Asmongold ❤️ 🙏, @Hunter4J @Wario64 bonk, @FF...\n",
       "4  865071  [@robo_james How about pizza dipped in water 🤦..."
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_tweets = pd.DataFrame.from_dict(data_tweets)\n",
    "data_tweets.rename(columns={0: \"id\", 1: \"tweets\"}, inplace = True)\n",
    "data_tweets[\"id\"] = data_tweets[\"id\"].astype(int)\n",
    "# data_tweets = data_tweets.set_index([\"id\"])\n",
    "data_tweets[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "16442544",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>tweets</th>\n",
       "      <th>name</th>\n",
       "      <th>screen_name</th>\n",
       "      <th>description</th>\n",
       "      <th>img_path</th>\n",
       "      <th>is_female</th>\n",
       "      <th>year_born</th>\n",
       "      <th>race</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12488</td>\n",
       "      <td>[YKAR, a futuristic sans serif font by @Emmera...</td>\n",
       "      <td>Chad Boyce</td>\n",
       "      <td>djsnipa1</td>\n",
       "      <td>Multimedia Developer, Graphic Designer, DJ, an...</td>\n",
       "      <td>profile pics/60147.jpeg</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1980.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>719703</td>\n",
       "      <td>[In other words, it’s good news about the vacc...</td>\n",
       "      <td>Tomato 😷</td>\n",
       "      <td>Tomato</td>\n",
       "      <td>🇭🇰Rise Up!</td>\n",
       "      <td>profile pics/60148.jpeg</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1985.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>749003</td>\n",
       "      <td>[would it be fair to call lil nas x the first ...</td>\n",
       "      <td>A ring made from a spoon --- E83.31</td>\n",
       "      <td>IYQbd</td>\n",
       "      <td>Has the kind of luck that turns a professional...</td>\n",
       "      <td>profile pics/60150.jpeg</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1982.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>822540</td>\n",
       "      <td>[@Asmongold ❤️ 🙏, @Hunter4J @Wario64 bonk, @FF...</td>\n",
       "      <td>parker</td>\n",
       "      <td>parker</td>\n",
       "      <td>gotta go fast</td>\n",
       "      <td>profile pics/60153.jpeg</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1979.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>865071</td>\n",
       "      <td>[@robo_james How about pizza dipped in water 🤦...</td>\n",
       "      <td>Kevin Jones</td>\n",
       "      <td>kevinj</td>\n",
       "      <td></td>\n",
       "      <td>profile pics/60154.jpeg</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       id                                             tweets  \\\n",
       "0   12488  [YKAR, a futuristic sans serif font by @Emmera...   \n",
       "1  719703  [In other words, it’s good news about the vacc...   \n",
       "2  749003  [would it be fair to call lil nas x the first ...   \n",
       "3  822540  [@Asmongold ❤️ 🙏, @Hunter4J @Wario64 bonk, @FF...   \n",
       "4  865071  [@robo_james How about pizza dipped in water 🤦...   \n",
       "\n",
       "                                  name screen_name  \\\n",
       "0                           Chad Boyce    djsnipa1   \n",
       "1                             Tomato 😷      Tomato   \n",
       "2  A ring made from a spoon --- E83.31       IYQbd   \n",
       "3                               parker      parker   \n",
       "4                          Kevin Jones      kevinj   \n",
       "\n",
       "                                         description                 img_path  \\\n",
       "0  Multimedia Developer, Graphic Designer, DJ, an...  profile pics/60147.jpeg   \n",
       "1                                         🇭🇰Rise Up!  profile pics/60148.jpeg   \n",
       "2  Has the kind of luck that turns a professional...  profile pics/60150.jpeg   \n",
       "3                                      gotta go fast  profile pics/60153.jpeg   \n",
       "4                                                     profile pics/60154.jpeg   \n",
       "\n",
       "   is_female  year_born  race  \n",
       "0        0.0     1980.0   4.0  \n",
       "1        0.0     1985.0   4.0  \n",
       "2        0.0     1982.0   5.0  \n",
       "3        0.0     1979.0   4.0  \n",
       "4        0.0     1995.0   4.0  "
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alldata = pd.merge(data_tweets, data_profile, on='id')\n",
    "# alldata = pd.concat([data_tweets, data_profile], axis=1)\n",
    "alldata = pd.merge(alldata, user_label, on='id')\n",
    "alldata[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "38583597",
   "metadata": {},
   "outputs": [],
   "source": [
    "alldata.to_csv(\"data_race_pred.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "854f51db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3276\n",
      "4132\n"
     ]
    }
   ],
   "source": [
    "print(len(data))\n",
    "print(len(user_label))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
